package com.tianya.domain.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * @author TianYaGuoKe
 * @date 2025/5/25 11:20
 * @description ProgressStatus
 */
public enum ProgressStatus {
    FINISHED(2, "已完成"),
    UNFINISHED(1, "进行中");

    @EnumValue
    private Integer code;
    private String desc;

    ProgressStatus(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @JsonValue
    public Integer getCode() {
        return code;
    }

    // 告诉 Jackson 反序列化时根据数字 code 解析枚举
    @JsonCreator
    public static ProgressStatus fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (ProgressStatus status : ProgressStatus.values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("无效的状态码：" + code);
    }
}
